//
//  PasswordSetViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/11/16.
//  Copyright © 2015年 RuiBen. All rights reserved.
//

#import "PasswordSetViewController.h"

@interface PasswordSetViewController ()

@end

@implementation PasswordSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _passwordOldTextField.secureTextEntry=YES;
    _passwordNewTextField.secureTextEntry=YES;
    _passwordNewAgainTextField.secureTextEntry=YES;
    [_passwordSetAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_passwordSetAlphaView addTarget:self action:@selector(passwordSetAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
}
-(IBAction)confirmChangePasswordBtn:(id)sender
{
    
    
    if ([_passwordNewTextField.text isEqualToString:_passwordNewAgainTextField.text]&&_passwordOldTextField.text.length>0) {
        if ([Global getLoginToken].length>0) {
            [Global showIndeterminateHudSub:@"请稍后。。。" delay:30 view:self.view];
            NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
            
            [params setObject:[Global getLoginToken] forKey:@"Token"];
            [params setObject:[Global md5:_passwordOldTextField.text] forKey:@"OldPassWord"];
            [params setObject:[Global md5:_passwordNewTextField.text] forKey:@"NewPassWord"];
            
            
            [HttpRequest requestData:@"System/UpdatePassWord" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    //NSLog(@"severddd===%@",severDataDict.dataDict);
                    // [Global hideProgressHUDInternal:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                       
                        _passwordNewTextField.text=@"";
                        _passwordOldTextField.text=@"";
                        _passwordNewAgainTextField.text=@"";
                        if ([self.delegate respondsToSelector:@selector(resetPasswordSuccess:)]) {
                            [self.delegate resetPasswordSuccess:requestResultStr];
                            }
                        
                    }
                    else
                    {
                        // NSLog(@"loginnnnnnnnn");
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        //  [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                          [Global loginViewController:self noteStr:requestResultStr];
                            //[Global loginViewController:self];
                        }
                        
                        
                    }
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    [Global showTextHudSub:@"连接失败" view:self.view];
                    
                }
            }];
            
        }
        
    }
    else
    {
        if (![_passwordNewTextField.text isEqualToString:_passwordNewAgainTextField.text]) {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"新密码填写不一致" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
        else if (_passwordOldTextField.text.length==0)
        {
            UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请填写旧密码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        }
    }
}

-(void)passwordSetAlphaViewClick
{
    if (self.view!=nil) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
